package activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;

import com.laoxinwen.app.R;

import java.text.SimpleDateFormat;
import java.util.Date;

import activity.main.MainActivity;
import common.BaseActivity;
import common.UserConfig;

public class StartupActivity extends BaseActivity {
    private boolean activityClicked = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_startup);
        //        try{
        //            ApplicationInfo appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        //            String channel =appInfo.metaData.getString("UMENG_CHANNEL");
        //            if("S360".equals(channel)){
        //                f(R.id.logo).setVisibility(View.VISIBLE);
        //            }
        //        }catch (Exception e){
        //        }

        if (UserConfig.isFirstUse()) {
            Intent it = new Intent(StartupActivity.this, WelcomeActivity.class);
            startActivity(it);
            finish();
        } else {
            //活动有效期
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String date = dateFormat.format(new Date());
            if(date.equals("2015-06-29") || date.equals("2015-06-30") || date.equals("2015-07-01")) {
                View activityImg = f(R.id.activity);
                activityImg.setVisibility(View.VISIBLE);
            }

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    if(activityClicked) {
                        return;
                    }
                    Intent it = new Intent(StartupActivity.this, MainActivity.class);
                    startActivity(it);
                    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                    finish();
                }
            }, 1500);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.activity:
                activityClicked = true;
                Intent it = WebviewActivity.getIntent("我们练习独孤九剑，找你们当陪练", "http://www.zaoing.com/activity?app", this);
                startActivity(it);
                finish();
                break;
        }
    }
}
